package com.example.demo.arithmetic.datastructure.linkedlist;

import org.junit.Test;

/**
 * @Description: 双向链表的测试
 * @Author: LLL
 * @Date: 2020-03-14 12:35
 **/
public class DoubleLinkedListDemo {

    @Test
    public void testAdd() {
        // 创建节点
        DoubleNode node1 = new DoubleNode("宋江", "及时雨", 1);
        // 创建节点
        DoubleNode node2 = new DoubleNode("卢俊义", "玉麒麟", 2);
        // 创建节点
        DoubleNode node3 = new DoubleNode("吴用", "智多星", 3);
        // 创建节点
        DoubleNode node4 = new DoubleNode("林冲", "豹子头", 4);
        // 创建一个双线链表
        DoubleLinkedList linkedList = new DoubleLinkedList();
        linkedList.add(node1);
        linkedList.add(node2);
        linkedList.add(node3);
        linkedList.add(node4);
        // 打印
        System.out.println("原始双向链表");
        linkedList.list();
        System.out.println("修改双向链表");
        DoubleNode nod5 = new DoubleNode("公孙胜", "入云龙", 4);
        linkedList.update(nod5);
        System.out.println("修改后的双向链表");
        linkedList.list();
        System.out.println("删除双向链表");
        linkedList.delete(node1);
        linkedList.list();
    }

    @Test
    public void testAddByOrder() {
        // 创建节点
        DoubleNode node1 = new DoubleNode("宋江", "及时雨", 1);
        // 创建节点
        DoubleNode node2 = new DoubleNode("卢俊义", "玉麒麟", 2);
        // 创建节点
        DoubleNode node3 = new DoubleNode("吴用", "智多星", 3);
        // 创建节点
        DoubleNode node4 = new DoubleNode("林冲", "豹子头", 4);
        // 创建一个双线链表
        DoubleLinkedList linkedList = new DoubleLinkedList();

        linkedList.addByOrder(node2);
        linkedList.addByOrder(node3);
        linkedList.addByOrder(node4);
        linkedList.addByOrder(node1);
        // 打印
        System.out.println("原始双向链表");
        linkedList.list();
    }

    @Test
    public void testList() {

    }
}
